/**
 * @Description: 解决移动端 点击事件延迟问题
 * @Author BPF
 * @create 2021/5/14 18:15
 */
import FastClick from 'fastclick'

export default {
  // eslint-disable-next-line no-unused-vars
  install: app => {
    FastClick.prototype.focus = function (targetElement) {
      var length
      // Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724.
      if (
        targetElement.setSelectionRange &&
        targetElement.type.indexOf('date') !== 0 &&
        targetElement.type !== 'time' &&
        targetElement.type !== 'month'
      ) {
        length = targetElement.value.length

        targetElement.focus()

        targetElement.setSelectionRange(length, length)
      } else {
        targetElement.focus()
      }
    }
    if ('addEventListener' in document) {
      document.addEventListener(
        'DOMContentLoaded',
        function () {
          new FastClick(document.body)
        },
        false
      )
    }
  }
}
